package com.probox.modules.controller.customer;

import com.probox.common.core.utils.poi.ExcelUtil;
import com.probox.common.core.web.controller.BaseController;
import com.probox.common.core.web.domain.AjaxResult;
import com.probox.common.core.web.page.TableDataInfo;
import com.probox.common.entity.domain.customer.CustomerInfoAccountToken;
import com.probox.common.entity.service.customer.ICustomerInfoAccountTokenService;
import com.probox.common.log.annotation.Log;
import com.probox.common.log.enums.BusinessType;
import com.probox.common.security.annotation.PreAuthorize;
import com.probox.systemApi.model.LoginUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


/**
 * 客户信息TOKENController
 *
 * @author zhusiyu
 * @date 2021-05-25
 */
@Api(value = "客户模块", tags = {"客户账号token信息后台操作接口"})
@RestController
@RequestMapping("/customer/customerAccountToken")
public class CustomerInfoAccountTokenController extends BaseController {
    @Autowired
    private ICustomerInfoAccountTokenService customerInfoAccountTokenService;

    /**
     * 查询客户信息TOKEN列表
     */
    @ApiOperation(value="查询客户信息TOKEN列表")
    @PreAuthorize(hasPermi = "customerAccountToken:customerAccountToken:list")
    @GetMapping("/list")
    public TableDataInfo list(CustomerInfoAccountToken customerInfoAccountToken) {
        startPage();
        List<CustomerInfoAccountToken> list = customerInfoAccountTokenService.queryList(customerInfoAccountToken);
        return getDataTable(list);
    }

    /**
     * 导出客户信息TOKEN列表
     */
    @ApiOperation(value="导出客户信息TOKEN列表")
    @PreAuthorize(hasPermi = "customerAccountToken:customerAccountToken:export")
    @Log(title = "客户信息TOKEN", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomerInfoAccountToken customerInfoAccountToken) throws IOException {
        List<CustomerInfoAccountToken> list = customerInfoAccountTokenService.queryList(customerInfoAccountToken);
        ExcelUtil<CustomerInfoAccountToken> util = new ExcelUtil<CustomerInfoAccountToken>(CustomerInfoAccountToken.class);
        util.exportExcel(response, list, "客户信息TOKEN数据");
    }

    /**
     * 获取客户信息TOKEN详细信息
     */
    @ApiOperation(value="获取客户信息TOKEN详细信息")
    @PreAuthorize(hasPermi = "customerAccountToken:customerAccountToken:query")
    @GetMapping(value = "/{tokenId}")
    public AjaxResult getInfo(@PathVariable("tokenId") Long tokenId) {
        return AjaxResult.success(customerInfoAccountTokenService.selectCustomerInfoAccountTokenById(tokenId));
    }

    /**
     * 新增客户信息TOKEN
     */
    @ApiOperation(value="新增客户信息TOKEN")
    @PreAuthorize(hasPermi = "customerAccountToken:customerAccountToken:add")
    @Log(title = "客户信息TOKEN", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerInfoAccountToken customerInfoAccountToken) {
        return toAjax(customerInfoAccountTokenService.insertCustomerInfoAccountToken(customerInfoAccountToken));
    }

    /**
     * 修改客户信息TOKEN
     */
    @ApiOperation(value="修改客户信息TOKEN")
    @PreAuthorize(hasPermi = "customerAccountToken:customerAccountToken:edit")
    @Log(title = "客户信息TOKEN", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerInfoAccountToken customerInfoAccountToken) {
        return toAjax(customerInfoAccountTokenService.updateCustomerInfoAccountToken(customerInfoAccountToken));
    }

    /**
     * 删除客户信息TOKEN
     */
    @ApiOperation(value="删除客户信息TOKEN")
    @PreAuthorize(hasPermi = "customerAccountToken:customerAccountToken:remove")
    @Log(title = "客户信息TOKEN", businessType = BusinessType.DELETE)
    @DeleteMapping("/{tokenIds}")
    public AjaxResult remove(@PathVariable Long[] tokenIds) {
        return toAjax(customerInfoAccountTokenService.deleteCustomerInfoAccountTokenByIds(tokenIds));
    }

    /**
     * 新增客户信息TOKEN
     */
    @ApiOperation(value="新增客户信息TOKEN")
    @PostMapping("/info/addCustomerToken")
    public boolean addCustomerToken(@RequestBody LoginUser loginUser) {
        return customerInfoAccountTokenService.addCustomerToken(loginUser);
    }
}
